﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace ZhaoPin.Mii
{
    public partial class DeleteUser : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName.Equals("Delete"))
            {
                Guid g = Guid.Parse(e.CommandArgument.ToString());
                RecruitContainer rc = new RecruitContainer();
                var m = from p in rc.People where p.Id.Equals(g) select p;
                Person person = m.Single();
                Membership.DeleteUser(person.IdentityCardNumber, true);
                rc.DeleteObject(person);
                rc.SaveChanges();
                var m2 = from p in rc.People where p.IdentityCardNumber.Contains(tbIdentityCardNumber.Text) select p;
                GridView1.DataSource = m2;
                GridView1.DataBind();
                rc.Dispose();
            }
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            RecruitContainer rc = new RecruitContainer();
            var m = from p in rc.People where p.IdentityCardNumber.Contains(tbIdentityCardNumber.Text) select p;
            GridView1.DataSource = m;
            GridView1.DataBind();
            rc.Dispose();
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {

        }

    }
}